<template>
  <div class="container">
      <div class="handle-box">
          <span style="padding: 8px">名称：</span>
          <el-input v-model="query.title" placeholder="标签名称" class="handle-input mr10" style="width: 20%"></el-input>
          <span style="padding: 8px"></span>
          <el-button type="success" size="medium" icon="el-icon-search" @click="initAjaxMethod">搜索</el-button>
          <!-- <el-button type="warning" size="medium" icon="el-icon-refresh-left" @click="reset">重置</el-button> -->
      </div>
      <div class="roleInput">
          <!-- <el-button type="primary" size="medium" @click="handleAdd" v-if="roulShowList.btn1.type">新建一级类目</el-button> -->
           <!-- <el-button type="primary" size="medium" @click="handleAdd" v-if="roulShowList.btn1.type">添加</el-button> -->
      </div>



      <div class="handle-box">
                <!-- <el-button type="primary" icon="el-icon-document-add" size="small" @click="createMethod">添加学员</el-button> -->
            
                <!-- <el-button type="warning" size="small" @click="stundetDialog=true">学员照片下载</el-button> -->

                 <div class="base-button-top">
                    <div>
                         <span>已付总额 {{cose1}}元;</span>         &nbsp;  &nbsp;   

						 <span>已绑教师{{ybjs}}人;</span>         &nbsp;  &nbsp;   
						 <span>已绑学生及家长{{ybxs}}人;</span>         &nbsp;  &nbsp;   
						 <span>教师人数{{jszj}}人;</span>         &nbsp;  &nbsp;  
						 <span>学生人数{{xszj}}人;</span> 

                        <!-- <span>总人数：{{persontotal}}</span> -->
                 
                        <!-- <span>已排班：{{paibannum1}}</span>   -->
                    </div>  
 

                 </div>
            </div>

      

      <div>
          <el-table
              :data="tableData"
              style="width: 100%; margin-bottom: 20px"
              row-key="sid"
              border
              :default-expand-all="false"
              :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
          >
              

              <el-table-column label="序号"
                       align="center"
                       width="100"
                       fixed>
                <template slot-scope="scope">{{scope.$index+(query.pageIndex - 1) * query.pageSize + 1}}</template>
            </el-table-column>


            		 

              <!-- <el-table-column prop="sid" label="ID" align="center"></el-table-column> -->
              <el-table-column prop="date" label="时间" align="center"></el-table-column>
              <el-table-column prop="cose" label="营业额" align="center"></el-table-column>
              <el-table-column prop="count" label="订单数" align="center"></el-table-column>
              <el-table-column prop="total_price1" label="在线支付" align="center"></el-table-column>
              <el-table-column prop="total_price2" label="现金支付" align="center"></el-table-column>
              <!-- <el-table-column prop="description3" label="一级标题" align="center"></el-table-column> -->
            
              

              <!-- <el-table-column prop="status" label="是否开启" width="100" align="center">
                  <template slot-scope="scope">
                      <el-tag v-if="scope.row.status == 1" type="success">是</el-tag>
                      <el-tag v-if="scope.row.status == 0" type="info">否</el-tag>
                  </template>
              </el-table-column> -->
              <el-table-column label="操作" align="center" width="420">
                  <template slot-scope="scope">
                  
                      <!-- <el-button v-if="roulShowList.btn3.type" icon="el-icon-edit" type="text" @click="handleEdit(scope.row)"
                          >编辑</el-button
                      > -->
                      <!-- <span style="padding: 8px"></span>
                      <el-switch
                          v-if="roulShowList.btn4.type"
                          v-model="scope.row.status == 1 ? true : false"
                          active-color="#13ce66"
                          inactive-color="#eeeeee"
                          active-text="启用"
                          inactive-text="停用"
                          @change="updatesw(scope.row, 1)"
                      >
                      </el-switch> -->
        
                      <!-- <span v-if="roulShowList.btn2.type">
                          <el-popconfirm title="确定删除吗22？" @confirm="handleDelete(scope.row)">
                              <el-button type="text" slot="reference" icon="el-icon-delete" style="color: #f56c6c">删除2</el-button>
                          </el-popconfirm>
                      </span> -->


                       <!-- <el-button @click="handleDelete(scope.row)"
                   type="text"
                   size="small"
                   icon="el-icon-delete"
                   class="red">删除</el-button> -->


                    <!-- <el-popconfirm  title="确定删除吗？" @confirm="handleDelete(scope.row.id, scope.row.title)">
                         <el-button type="text" slot="reference" >删除</el-button>
                       </el-popconfirm> -->

                       
        <!-- <el-button @click="handleDelete(scope.row)"
                   type="text"
                   size="small"
                   icon="el-icon-delete"
                   class="red">删除</el-button> -->


                  </template>
              </el-table-column>
          </el-table>
          <div class="pagination">
              <el-pagination
                  layout="sizes,total, prev, pager, next, jumper"
                  :current-page="query.pageIndex"
                  :page-size="query.pageSize"
                  :page-sizes="[10, 20, 50, 100, 150, 200]"
                  @size-change="handleSizeChange"
                  :total="pageTotal"
                  @current-change="handlePageChange"
              ></el-pagination>
          </div>
      </div>
      <!--添加组织名称-->
 
  </div>
</template>

<script>
import api from '@/api/index';
import imgUpload from '../../commons/ImgUpload';
import { getdate } from '@/utils/utils';
import _ from 'lodash';
import axios from "axios";
export default {
  components: { imgUpload },
  data() {
      return {
          rbacTitle: '',
          editOrAdd: 1,
          editVisible: false,
          tableData: [],
          cascaderData: [],
          options: [],
         
          parent_id: 0,
          sname: '',
          thumb: '',
          ssort: 0,
          is_show: 0,
          id: null,
          query: {
              pageIndex: 1,
              pageSize: 10,
              sname: ''
          },
          pageTotal: 0,
     
          roulShowList: {
              btn1: { rule: 'tagmanage,main,add', type: true, name: '新增' },
              btn2: { rule: 'tagmanage,main,del', type: true, name: '删除' },
              btn3: { rule: 'tagmanage,main,edit', type: true, name: '编辑' },
              btn4: { rule: 'tagmanage,main,edit_disabled', type: true, name: '禁用' },
              btn5: { rule: 'tagmanage,main,edit_warn', type: true, name: '告警' }
          },
          cose1:0,
          ybjs:0,
          ybxs:0,
          jszj:0,
          xszj:0, 


      };
  },
  filters: {
      formDate(val) {
          if (!val) return '';
          return getdate(val);
      }
  },
  mounted() {
      this.initAjaxMethod();
      // this.roleMethod()
  },
  methods: {
      reset() {
          this.query.pageIndex = 1;
          this.query.sname = '';
          this.initAjaxMethod();
      },
      // 分页导航
      handlePageChange(val) {
          this.$set(this.query, 'pageIndex', val);
          this.initAjaxMethod();
      },
      handleSizeChange(e) {
          this.query.pageSize = e;
          this.initAjaxMethod();
      },
      //初始化页面列表
      initAjaxMethod() {
          const loading = this.$loading({ text: '加载中...' });
          this.$http
              .post(api.Xygl_INDEX, {
                  page: this.query.pageIndex,
                  listRows: this.query.pageSize,
                  sname: this.query.sname,
                  type:'semester'
              })
              .then((res) => {
                  loading.close();
                  if (res.code == 1) {
                      let list = Array.isArray(res.data.list) ? res.data.list : [];
                      // list.forEach((item) => {
                      //     item.childrenNum = 0;
                      //     if (Array.isArray(item.children) && item.children.length > 0) {
                      //         item.childrenNum = item.children.length;
                      //     }
                      // });
                      this.tableData = list;
                      this.pageTotal = res.data.total;
                      this.ybjs = res.data.ybjs;
                      this.ybxs = res.data.ybxs;
                      this.jszj = res.data.jszj;
                      this.xszj = res.data.xszj;
                      this.cose1 = res.data.cose1;
        
                  } else {
                      this.$message.error(res.msg);
                  }
              })
              .catch((err) => {
                  this.$message.error(err.msg);
              });
      },
      //新增
      handleAdd() {
          this.editVisible = true;
          this.editOrAdd = 1;
          this.parent_id = 0;
          this.sname = '';
           this.description3 = '';   
          this.description = '';  
          this.description2 = '';  
          this.thumb = '';
          this.sort = 0;
          this.id = null;
          this.rbacTitle = '新增';
          this.level = 0;
      },
      //点击编辑
      handleEdit(data) {
          console.log(data);
          this.editVisible = true;
          this.editOrAdd = 2;
          this.id = data.sid;
        //   this.parent_id = data.parent_id;
          this.sname = data.sname;
          this.ssort = data.ssort;
          this.is_show = data.is_show;
          this.thumb = data.thumb;
          this.rbacTitle = data.level == 0 ? '编辑' : '编辑';
        //   this.level = data.level;
            
        //   this.description = data.description; 
           
      },
  
      //弹出框确定
      saveEdit() {
          if (!this.sname || this.sname == '') {
              return this.$message.error('请填写名称!');
          }
          let parmam = {  
              sname: this.sname,
            
              ssort: this.ssort,
              is_show: this.is_show,
              thumb: this.thumb,
              detail: '新增：' + this.sname
          };
          let url = api.Semester_ADD;
          if (this.editOrAdd == 2) {
              parmam.id = this.id;
              parmam.detail = '编辑：' + this.sname;
              url = api.Semester_EDIT;
          }
          parmam.type = "semester";
          const loading = this.$loading({ text: '保存中...' });
          this.$http
              .post(url, parmam)
              .then((res) => {
                  loading.close();
                  console.log('新增规则', res);
                  if (res.code == 1) {
                      this.$message.success('操作成功');
                      this.editVisible = false;
                      this.initAjaxMethod();
                  } else {
                      this.$message.error(res.msg);
                  }
              })
              .catch((err) => {
                  this.$message.error(err.msg);
              });
      },
   
      //点击删除
    
      //删除
      handleDelete(data){
      this.delAjaxMethod(data.sid);
      },

   delAjaxMethod(ids){
    this.$confirm('此操作将删除此条信息, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      const loading = this.$loading({ text: '加载中...' });
      this.$http.post(api.Semester_DEL, {ids:ids})
            .then((res) => {
              loading.close();
              console.log('项目列表', res)
              if (res.code == 1) {
                this.$message.success('删除成功');
                this.query.pageIndex=1;
                this.initAjaxMethod()
              } else {
                this.$message.error(res.msg);
              }
            })
            .catch((err) => {
              this.$message.error(err.msg);
            })
    })
  },

      roleMethod() {
          this.$http.post(this.$API.GET_TRR_PAGE, { rule: 'tagmanage,main' }).then((res) => {
              console.log('页面权限', res);
              if (res.data === 'admin') {
                  for (let i in this.roulShowList) {
                      this.roulShowList[i].type = true;
                  }
              } else {
                  res.data.forEach((item) => {
                      for (let j in this.roulShowList) {
                          if (item.rule == this.roulShowList[j].rule) {
                              this.roulShowList[j].type = true;
                          }
                      }
                  });
              }
          });
      }
  }
};
</script>


<style scoped>
.roleInput {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin: 20px 0;
}
.list-title {
  /* padding:7px; */
  height: 32px;
  display: flex;
  align-items: center;
}
</style>